// -----------------------------------------------------------------------
//  <copyright file="NotSpecification.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2024 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://www.dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2024-04-18 13:04</last-date>
// -----------------------------------------------------------------------

using DaprPlus.Domain.Entity;


namespace DaprPlus.Specifications;

public class NotSpecification<T> : SpecificationBase<T> where T : IEntity
{
    public NotSpecification(ISpecification<T> spec) : base(spec.Criteria.Not())
    {
        // 复制包含信息
        foreach (var item in spec.Includes)
        {
            AddInclude(item);
        }

        foreach (var item in spec.IncludeStrings)
        {
            AddInclude(item);
        }

        // 复制排序信息
        foreach (var item in spec.OrderExpressions)
        {
            AddOrderBy(item.OrderByExpression, item.IsDescending);
        }

        foreach (var item in spec.OrderStrings)
        {
            AddOrderBy(item.FieldName, item.IsDescending);
        }

        // 复制分页信息
        if (spec.IsPagingEnabled)
        {
            ApplyPaging(spec.Skip, spec.Take);
        }
    }
}
